/*!
 * Ext JS Library 4.0 桌面式架构开发概要 - By Jiang.zx
 * 
 * 模块配置：一，配置requires				//引入相关的模块
 * 		 		 二，配置getModules()		//模块实例化
 * 		  		 三，配置shortcuts    			//点击桌面图标事件
 * 		 		 五，配置quickStart  			//任务栏上的快捷方式
 * 模块开发：一，extend: 'Ext.ux.desktop.Module'
 * 				 二，this.launcher：表示增加开始菜单条目
 * 				 三，createWindow：创建窗口
 * 
 * 路径问题：跟jsp中的路径对应
 * 
 */

Ext.define('MyDesktop.App', {
    extend: 'Ext.ux.desktop.App',

    requires: [
        'Ext.window.MessageBox',
        'Ext.ux.desktop.ShortcutModel',
        
//        'MyDesktop.SystemStatus',
//        'MyDesktop.VideoWindow',
//        'MyDesktop.GridWindow',
//        'MyDesktop.TabWindow',
//        'MyDesktop.AccordionWindow',
//        'MyDesktop.Notepad',
//        'MyDesktop.BogusMenuModule',
//        'MyDesktop.BogusModule',
        'MyDesktop.Settings',
        //注册自定义模块
         'MyDesktop.Tshop',
         'MyDesktop.Tdist',
         'MyDesktop.Tprod',
         'MyDesktop.Tord'
    ],

    init: function() {
        // custom logic before getXYZ methods get called...

        this.callParent();

        // now ready...
    },

    getModules : function(){			/*桌面按钮事件*/
        return [
//            new MyDesktop.VideoWindow(),
//            new MyDesktop.Blockalanche(),
//            new MyDesktop.SystemStatus(),
//            new MyDesktop.GridWindow(),
//            new MyDesktop.TabWindow(),
//            new MyDesktop.AccordionWindow(),
//            new MyDesktop.Notepad(),
//            new MyDesktop.BogusMenuModule(),
//            new MyDesktop.BogusModule(),
            
            //注册自定义模块
			new MyDesktop.Tshop(),
            new MyDesktop.Tdist(),
            new MyDesktop.Tprod(),
            new MyDesktop.Tord()
        ];
    },

    getDesktopConfig: function () {
        var me = this, ret = me.callParent();

        return Ext.apply(ret, {
            //cls: 'ux-desktop-black',

            contextMenuItems: [		/*鼠标右键事件*/
                { text: '修改配置', handler: me.onSettings, scope: me }
            ],

            shortcuts: Ext.create('Ext.data.Store', {	/*单击桌面图标事件*/
                model: 'Ext.ux.desktop.ShortcutModel',
                data: [
//                    { name: 'Grid Window', iconCls: 'grid-shortcut', module: 'grid-win' },
//                    { name: 'Accordion Window', iconCls: 'accordion-shortcut', module: 'acc-win' },
//                    { name: 'Notepad', iconCls: 'notepad-shortcut', module: 'notepad' },
//                    { name: 'System Status', iconCls: 'cpu-shortcut', module: 'systemstatus'},
                    
                    //注册自定义模块
	                   { name: '店铺管理', 	iconCls: 'img_shopcart_large', module: 'tshop-win'},
	                   { name: '经销商管理', iconCls: 'img_dist_large', module: 'tdist-win'},
	                   { name: '产品管理', iconCls: 'img_prod_large', module: 'tprod-win'},
	                   {name:'订单管理',iconCls:'img_ord_large',module:'ord-win'}
                ]
            }),

            wallpaper: 'wallpapers/Blue-Sencha.jpg',  /*系统默认墙纸*/
            wallpaperStretch: false			/*宽高100%显示*/
        });
    },

    // config for the start menu
    getStartConfig : function() {
        var me = this, ret = me.callParent();

        return Ext.apply(ret, {
            title: '菜单',
            iconCls: 'user',
            height: 300,
            toolConfig: {
                width: 100,
                items: [
                    {
                        text:'Settings',
                        iconCls:'settings',
                        handler: me.onSettings,
                        scope: me
                    },
                    '-',
                    {
                        text:'Logout',
                        iconCls:'logout',
                        handler: me.onLogout,
                        scope: me
                    }
                ]
            }
        });
    },

    getTaskbarConfig: function () {
        var ret = this.callParent();

        return Ext.apply(ret, {			/**任务栏快捷图标按钮*/
            quickStart: [		
//                { name: 'Accordion Window', iconCls: 'accordion', module: 'acc-win' },
//                { name: 'Grid Window', iconCls: 'icon-grid', module: 'grid-win' }
            ],
            trayItems: [
                { xtype: 'trayclock', flex: 1 }
            ]
        });
    },

    onLogout: function () {
        Ext.Msg.confirm('Logout', 'Are you sure you want to logout?',function(buttonId){
        	if(buttonId == 'yes'){
        		document.location = Bleext.Constants.DESKTOP_LOGOUT_URL;
        	}
        });
    },

    onSettings: function () {
        var dlg = new MyDesktop.Settings({
            desktop: this.desktop
        });
        dlg.show();
    }
});
